<?php


namespace App\Http\Controllers\Auth;


use App\Enum\APIEnum;
use App\Exceptions\APIHttpException;
use App\Http\Controllers\Controller;
use App\Http\Middleware\Auth;
use App\Http\Service\Auth\LoginService;

class Login extends Controller
{

    /**
     * pc-退出登录
     *
     * @return \Illuminate\Http\JsonResponse
     */
    public function logout()
    {
        /*PC-SSO-退出登录*/
        LoginService::logout(Auth::user('uniqid'));
        return APIHttpException::success();
    }


    /**
     * pc端-登录
     *
     * @return \Illuminate\Http\JsonResponse
     * @throws APIHttpException
     */
    public function login()
    {
        $token = request()->input('token');
        /*解析登录信息,获取登录人工号*/
        $workcode = LoginService::user($token);
        /*开启工号登录允许?*/
        if (config('ext.app_login') === true && empty($workcode)) {
            $workcode = request()->input('workcode', $token);
        }
        /*无法识别登录工号*/
        if (empty($workcode)) {
            throw new APIHttpException('登录信息无效', APIEnum::LOGIN_VOID['code']);
        }
        /*让指定工号处于登录状态*/
        return APIHttpException::success(LoginService::login($workcode));
    }

}





/**
 * Login.php
 *
 * 说明:
 *
 * 修改历史
 * ----------------------------------------
 * 2020/5/19 18:25:00   操作:创建
 **/
